package com.bjqh.edu.UI.Activity.StudentPersonal;

import android.Manifest;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.baijiahulian.common.utils.StringUtils;
import com.bjqh.edu.Base.AppConstants;
import com.bjqh.edu.Base.EasyActivity;
import com.bjqh.edu.Base.SelectPicPopupWindow;
import com.bjqh.edu.Bean.Grade;
import com.bjqh.edu.Bean.User;
import com.bjqh.edu.BuildConfig;
import com.bjqh.edu.MainActivity;
import com.bjqh.edu.R;
import com.bjqh.edu.UI.Utils.CropUtils;
import com.bjqh.edu.UI.Utils.DialogPermission;
import com.bjqh.edu.UI.Utils.FileUtil;
import com.bjqh.edu.UI.Utils.PermissionUtil;
import com.bjqh.edu.UI.Utils.SharedPreferenceMark;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.generic.RoundingParams;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.Gson;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.HttpParams;

import java.io.File;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

public class PersonalInformationActivity extends EasyActivity {
    private static final int REQUEST_CODE_TAKE_PHOTO = 1;
    private static final int REQUEST_CODE_ALBUM = 2;
    private static final int REQUEST_CODE_CROUP_PHOTO = 3;
    //声明选中项变量
    public int selectedCityIndex = 0;
    public List<Grade.RowsBean> gradeBean;
    @BindView(R.id.iv_back)
    ImageView ivBack;
    @BindView(R.id.tv_title)
    TextView tvTitle;
    @BindView(R.id.rl_top_tilte)
    RelativeLayout rlTopTilte;
    @BindView(R.id.user_avatar)
    SimpleDraweeView mSimpleDraweeView;
    @BindView(R.id.et_name)
    EditText etName;
    @BindView(R.id.et_phone)
    EditText etPhone;
    @BindView(R.id.et_age)
    EditText etAge;
    @BindView(R.id.et_school)
    EditText etSchool;
    @BindView(R.id.textView2)
    TextView textView2;
    @BindView(R.id.et_grade)
    TextView etGrade;
    @BindView(R.id.et_subject)
    TextView etSubject;
    @BindView(R.id.tv_ok)
    Button tvOk;
    @BindView(R.id.iv_subject)
    LinearLayout ivSubject;
    @BindView(R.id.iv_grade)
    LinearLayout ivGrade;

    @BindView(R.id.et_na)
    EditText etNa;
    String[] arrayGrade = new String[5];
    Dialog alertDialog;
    Dialog alertDialog2;
    Map<String, String> map = new HashMap<String, String>();
    Map<String, String> map2 = new HashMap<String, String>();
    private File file;
    private Uri uri;
    SelectPicPopupWindow menuWindow;
    String gradeId;
    User user;
    User.UserBean userBean;
    private List<String> courseId;
    private List<String> courseName;
    private String courseIdUp;
    private ProgressDialog dialog;

    private static final int REQUEST_PERMISSIONS = 0x044;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        Fresco.initialize(this);
        setContentView(R.layout.activity_personal_information);
        ButterKnife.bind(this);
        dialog = new ProgressDialog(this);
        dialog.setMessage("火速加载中…");
        initViews();
        OkGo.post(AppConstants.BASE_URL + "/user/userInfor.shtml")
                .tag(this)
                .cacheKey("cacheKey")
                .cacheMode(CacheMode.DEFAULT)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(String s, okhttp3.Call call, okhttp3.Response response) {
                        Log.e("个人信息", s);
                        Gson gson = new Gson();
                        user = gson.fromJson(s, User.class);
                        if (user.getMsg().equals("success")) {
                            removeDialog();

                            userBean = user.getUser();
                            GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources());
                            GenericDraweeHierarchy hierarchy = builder
                                    .setDesiredAspectRatio(1.0f)
                                    .setFailureImage(R.mipmap.tx)
                                    .setRoundingParams(RoundingParams.fromCornersRadius(100f))
                                    .build();
                            mSimpleDraweeView.setHierarchy(hierarchy);
                           /* DraweeController controller = Fresco.newDraweeControllerBuilder()
                                    .setUri(uri)
                                    .setAutoPlayAnimations(true)
                                    .build();*/
                            mSimpleDraweeView.setHierarchy(hierarchy);
                            mSimpleDraweeView.setImageURI(AppConstants.IMG_URL + userBean.getHeader());


                            if (userBean.getNickname() != null) {
                                etName.setText(userBean.getNickname());

                            }

                            etPhone.setText(userBean.getMobile());
                            etNa.setText(StringUtils.isEmpty(userBean.getName()) ? null : userBean.getName());
                            if (userBean.getAge() != 0) {
                                etAge.setText(userBean.getAge() + "");

                            }
                            if (userBean.getSchool() != null) {
                                etSchool.setText(userBean.getSchool());

                            }

                            OkGo.post(AppConstants.BASE_URL + "/admin/omMenu//datalist.shtml")
                                    .tag(this)
                                    .cacheKey("cacheKey")
                                    .cacheMode(CacheMode.DEFAULT)
                                    .params("flag", "0")
                                    .execute(new StringCallback() {
                                        @Override
                                        public void onSuccess(String s, Call call, Response response) {
                                            Log.e("年级列表", s);
                                            getValue(s);

                                        }
                                    });


                        }
                    }

                    @Override
                    public void onError(Call call, Response response, Exception e) {
                        Toast.makeText(PersonalInformationActivity.this, "报告小主，服务器被外星人偷走啦~~", Toast.LENGTH_SHORT).show();
                    }
                });


        initEvents();
        initPermission();
    }

    private void init() {

        file = new File(FileUtil.getCachePath(this), "user-avatar.jpg");
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            uri = Uri.fromFile(file);
        } else {
            //通过FileProvider创建一个content类型的Uri(android 7.0需要这样的方法跨应用访问)
//            uri = FileProvider.getUriForFile(PersonalInformationActivity.this, "com.yf.useravatar", file);
            uri = FileProvider.getUriForFile(PersonalInformationActivity.this, BuildConfig.APPLICATION_ID + ".provider", file);

        }
    }

    protected void initViews() {
        tvTitle.setText("个人信息");
        tvTitle.setVisibility(View.VISIBLE);
    }

    protected void initData() {


    }

    public void getValue(String s) {
        Gson gson = new Gson();
        Grade grade = gson.fromJson(s, Grade.class);
        gradeBean = grade.getRows();
        for (int i = 0; i < gradeBean.size(); i++) {
            if (null != userBean.getGradeid() && userBean.getGradeid() == new BigDecimal(gradeBean.get(i).getId()).intValue()) {
                etGrade.setText(gradeBean.get(i).getName());
            }
            arrayGrade[i] = gradeBean.get(i).getName();
            map2.put(gradeBean.get(i).getId(), gradeBean.get(i).getName());

        }

        // Toast.makeText(PersonalInformationActivity.this, "请求成功" + arrayGrade[0], Toast.LENGTH_SHORT).show();

        courseName = Arrays.asList(gradeBean.get(0).getCname().split(","));
        courseId = Arrays.asList(gradeBean.get(0).getContentid().split(","));


        alertDialog2 = new AlertDialog.Builder(this).setTitle("选择年级").setSingleChoiceItems(arrayGrade, 0, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                selectedCityIndex = which;
                courseName = Arrays.asList(gradeBean.get(selectedCityIndex).getCname().split(","));
                courseId = Arrays.asList(gradeBean.get(selectedCityIndex).getContentid().split(","));
                gradeId = gradeBean.get(selectedCityIndex).getId();
                userBean.setGradeid(new BigDecimal(gradeBean.get(selectedCityIndex).getId()).intValue());

                alertDialog = new AlertDialog.Builder(PersonalInformationActivity.this).setTitle("选择学科")

                        .setMultiChoiceItems(courseName.toArray(new String[courseName.size()]), null, new DialogInterface.OnMultiChoiceClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                        if (isChecked) {
                                            map.put(courseId.get(which), courseName.get(which));
                                        } else {
                                            map.remove(courseId.get(which));
                                        }
                                    }
                                }
                        ).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                //  course = courseId.split(",");

                                StringBuilder stringBuilder = new StringBuilder();
                                StringBuilder stringBuilder2 = new StringBuilder();

                                for (int i = 0; i < courseId.size(); i++) {
                                    if (map.get(courseId.get(i)) != null) {
                                        stringBuilder.append(map.get(courseId.get(i)) + ",");
                                    }
                                }
                                for (String key : map.keySet()) {
                                    stringBuilder2.append(key + ",");
                                }
                                if (stringBuilder.length() > 0) {
                                    etSubject.setText(stringBuilder.substring(0, stringBuilder.length() - 1));

                                }
                                if (stringBuilder2.length() > 0) {
                                    courseIdUp = stringBuilder2.substring(0, stringBuilder2.length() - 1);
                                    // Toast.makeText(PersonalInformationActivity.this, "学科ID" + courseId, Toast.LENGTH_SHORT).show();

                                }

                                dialog.dismiss();
                            }

                        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        }).create();


                //Toast.makeText(PersonalInformationActivity.this, "学科" + courseId, Toast.LENGTH_SHORT).show();
            }
        })
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        map.clear();
                        etGrade.setText(arrayGrade[selectedCityIndex]);

                        dialog.dismiss();
                    }

                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                }).create();


        // 创建一个AlertDialog建造者
        if (!com.ta.utdid2.android.utils.StringUtils.isEmpty(userBean.getCourse())) {
            boolean[] ck = new boolean[courseId.size()];
            List<String> ucids = Arrays.asList(userBean.getCourse().split(","));
            if (ucids.size() > 0) {
                String defaultCourse = null;
                for (int x = 0; x < courseId.size(); x++) {
                    if (ucids.contains(courseId.get(x))) {
                        ck[x] = true;
                        if (null == defaultCourse) {
                            defaultCourse = courseName.get(x);
                        } else {
                            defaultCourse = defaultCourse + "、" + courseName.get(x);
                        }
                    } else {
                        ck[x] = false;
                    }

                }
                etSubject.setText(defaultCourse);
            }
            alertDialog = new AlertDialog.Builder(PersonalInformationActivity.this).setTitle("选择学科")

                    .setMultiChoiceItems(courseName.toArray(new String[courseName.size()]), ck, new DialogInterface.OnMultiChoiceClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                                    if (isChecked) {
                                        map.put(courseId.get(which), courseName.get(which));
                                    } else {
                                        map.remove(courseId.get(which));
                                    }
                                }
                            }
                    ).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            //  course = courseId.split(",");
                            StringBuilder stringBuilder = new StringBuilder();
                            StringBuilder stringBuilder2 = new StringBuilder();

                            for (int i = 0; i < courseId.size(); i++) {
                                if (map.get(courseId.get(i)) != null) {
                                    stringBuilder.append(map.get(courseId.get(i)) + ",");
                                }
                            }
                            for (String key : map.keySet()) {
                                stringBuilder2.append(key + ",");
                            }
                            if (stringBuilder.length() > 0) {
                                etSubject.setText(stringBuilder.substring(0, stringBuilder.length() - 1));

                            }
                            if (stringBuilder2.length() > 0) {
                                courseIdUp = stringBuilder2.substring(0, stringBuilder2.length() - 1);
                                // Toast.makeText(PersonalInformationActivity.this, "学科ID" + courseId, Toast.LENGTH_SHORT).show();

                            }

                            dialog.dismiss();
                        }

                    }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    }).create();
        }


    }

    protected void initEvents() {
        ivBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ivSubject.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // 创建一个AlertDialog建造者
                if (null != userBean.getGradeid()) {
                    alertDialog.show();
                }

            }
        });
        ivGrade.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                gradeId = gradeBean.get(0).getId();
                alertDialog2.show();
            }
        });
        tvOk.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                if (TextUtils.isEmpty(etName.getText())) {

                    Toast.makeText(PersonalInformationActivity.this, "报告小主，昵称还没有填呢~", Toast.LENGTH_SHORT).show();
                    etName.requestFocus();
                    return;

                }
                if (TextUtils.isEmpty(etSchool.getText())) {

                    Toast.makeText(PersonalInformationActivity.this, "报告小主，学校还没有填呢~", Toast.LENGTH_SHORT).show();
                    etSchool.requestFocus();
                    return;

                }
                if (TextUtils.isEmpty(etAge.getText())) {

                    Toast.makeText(PersonalInformationActivity.this, "报告小主，年龄还没有填呢~", Toast.LENGTH_SHORT).show();
                    etAge.requestFocus();
                    return;

                }
                // Toast.makeText(PersonalInformationActivity.this, "学科" + courseId, Toast.LENGTH_SHORT).show();
                HttpParams params = AppConstants.initPram();
                params.put("name", etNa.getText().toString());
                params.put("nickname", etName.getText().toString());
                params.put("mobile", etPhone.getText().toString());
                if (gradeId != null && AppConstants.isNumeric(gradeId)) {
                    params.put("gradeid", gradeId);
                }
                if (null != userBean && 0 == userBean.getRole()) {
                    params.put("role", "0");
                } else {
                    Toast.makeText(PersonalInformationActivity.this, "身份异常", Toast.LENGTH_LONG).show();

                }

                if (courseIdUp != null) {
                    params.put("course", courseIdUp);

                }
                params.put("school", etSchool.getText().toString());
                params.put("age", etAge.getText().toString());
                if (file != null) {
                    params.put("file", file);
                }
                dialog.show();
                dialog.setCanceledOnTouchOutside(false);
                OkGo.post(AppConstants.BASE_URL + "/user/addOrUpdate.shtml")
                        .tag(this)
                        .cacheKey("cacheKey")
                        .cacheMode(CacheMode.DEFAULT)
                        .params(params)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(String s, Call call, Response response) {
                                Toast.makeText(PersonalInformationActivity.this, "报告小主，您的要求已完成。", Toast.LENGTH_SHORT).show();
                                startActivity(new Intent(PersonalInformationActivity.this, MainActivity.class));
                                finish();
                                removeDialog();

                            }

                            @Override
                            public void onError(Call call, Response response, Exception e) {
                                super.onError(call, response, e);
                                Toast.makeText(PersonalInformationActivity.this, "报告小主，服务器被外星人偷走啦~~", Toast.LENGTH_SHORT).show();
                                removeDialog();
                            }
                        });
            }
        });
        mSimpleDraweeView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                init();
                //实例化SelectPicPopupWindow
                menuWindow = new SelectPicPopupWindow(PersonalInformationActivity.this, itemsOnClick);
                //显示窗口
                menuWindow.showAtLocation(PersonalInformationActivity.this.findViewById(R.id.main), Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置
            }

        });

    }

    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {

        public void onClick(View v) {
            menuWindow.dismiss();
            switch (v.getId()) {
                case R.id.btn_take_photo:
                    //  Toast.makeText(PersonalInformationActivity.this, "拍照---", Toast.LENGTH_SHORT).show();
                    if (PermissionUtil.hasCameraPermission(PersonalInformationActivity.this)) {
                        uploadAvatarFromPhotoRequest();
                    }
                    break;
                case R.id.btn_pick_photo:
                    // Toast.makeText(PersonalInformationActivity.this, "相冊---", Toast.LENGTH_SHORT).show();
                    uploadAvatarFromAlbumRequest();
                    break;
                default:
                    break;
            }

        }

    };

    /**
     * photo
     */
    private void uploadAvatarFromPhotoRequest() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra(MediaStore.Images.Media.ORIENTATION, 0);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
        startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);
    }

    /**
     * album
     */
    private void uploadAvatarFromAlbumRequest() {
        Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
        photoPickerIntent.setType("image/*");
        startActivityForResult(photoPickerIntent, REQUEST_CODE_ALBUM);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode != -1) {
            return;
        }
        if (requestCode == REQUEST_CODE_ALBUM && data != null) {
            Uri newUri;
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
                newUri = Uri.parse("file:///" + CropUtils.getPath(this, data.getData()));
            } else {
                newUri = data.getData();
            }
            if (newUri != null) {
                startPhotoZoom(newUri);
            } else {
                // Toast.makeText(this, "没有得到相册图片", Toast.LENGTH_LONG).show();
            }
        } else if (requestCode == REQUEST_CODE_TAKE_PHOTO) {
            startPhotoZoom(uri);
        } else if (requestCode == REQUEST_CODE_CROUP_PHOTO) {
            uploadAvatarFromPhoto();
        }
    }

    private void uploadAvatarFromPhoto() {
        compressAndUploadAvatar(file.getPath());
    }

    private void compressAndUploadAvatar(String fileSrc) {
        final File cover = FileUtil.getSmallBitmap(this, fileSrc);
//        String mimeType = "image";
//        requestBody = RequestBody.create(MediaType.parse(mimeType), file);
//        String fileName = cover.getName();
//        photo = MultipartBody.Part.createFormData("portrait", fileName.substring(fileName.lastIndexOf("/") + 1, fileName.length()), requestBody);
        //Fresco设置圆形头像
        GenericDraweeHierarchyBuilder builder = new GenericDraweeHierarchyBuilder(getResources());
        GenericDraweeHierarchy hierarchy = builder
                .setDesiredAspectRatio(1.0f)
                .setFailureImage(R.mipmap.ic_launcher)
                .setRoundingParams(RoundingParams.fromCornersRadius(100f))
                .build();

        //加载本地图片
        Uri uri = Uri.fromFile(cover);
        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setOldController(mSimpleDraweeView.getController())
                .setUri(uri)
                .build();
        mSimpleDraweeView.setHierarchy(hierarchy);
        mSimpleDraweeView.setController(controller);
    }

    /**
     * 裁剪拍照裁剪
     *
     * @param uri
     */
    public void startPhotoZoom(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.putExtra("crop", "true");// crop=true 有这句才能出来最后的裁剪页面.
        intent.putExtra("aspectX", 1);// 这两项为裁剪框的比例.
        intent.putExtra("aspectY", 1);// x:y=1:1
//        intent.putExtra("outputX", 400);//图片输出大小
//        intent.putExtra("outputY", 400);
        intent.putExtra("output", Uri.fromFile(file));
        intent.putExtra("outputFormat", "JPEG");// 返回格式
        startActivityForResult(intent, REQUEST_CODE_CROUP_PHOTO);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        switch (requestCode) {

            case PermissionUtil.REQUEST_SHOWCAMERA:
                if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
                    // Permission Granted
                    uploadAvatarFromPhotoRequest();

                } else {
                    if (!SharedPreferenceMark.getHasShowCamera()) {
                        SharedPreferenceMark.setHasShowCamera(true);
                        new DialogPermission(this, "关闭摄像头权限影响扫描功能");

                    } else {
                    /*    Toast.makeText(this, "未获取摄像头权限", Toast.LENGTH_SHORT)
                                .show();*/
                    }
                }
                break;
            default:
                super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        }
    }

    private void removeDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    private void initPermission() {
        String[] permissions = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE};
        //检查权限
        if (ContextCompat.checkSelfPermission(this,
                Manifest.permission.CAMERA)
                != PackageManager.PERMISSION_GRANTED) {
            //判断权限是否被拒绝过
            if (ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.CAMERA)) {
                Toast.makeText(this, "用户曾拒绝打开相机权限", Toast.LENGTH_SHORT).show();
            } else {
                //注册相机权限
                ActivityCompat.requestPermissions(this,
                        permissions,
                        REQUEST_PERMISSIONS);
            }
        }
    }
}
